package com.lkbaby.home.controller.impl;

import com.lkbaby.home.controller.UserInfoController;
import com.lkbaby.home.entity.UserInfo;
import com.lkbaby.home.service.UserInfoService;
import com.lkbaby.home.util.ResponseDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * 用户数据(UserInfo)表控制层
 *
 * @author makejava
 * @since 2024-03-15 09:37:30
 */
@RestController
@RequestMapping("/userInfo")
public class UserInfoControllerImpl implements UserInfoController {

	@Autowired
	private UserInfoService userInfoService;

	@Override
	@RequestMapping("/login")
	public ResponseDto login(@RequestBody UserInfo userInfo) {

		if (Objects.isNull(userInfo) || Objects.isNull(userInfo.getUserName()) || Objects
				.isNull(userInfo.getUserName())) {
			return ResponseDto.buildError("非空校验失败");
		}

		UserInfo checkLogin = userInfoService.checkLogin(userInfo);

		if (Objects.nonNull(checkLogin)) {
			return ResponseDto.buildSuccess(checkLogin);
		}
		return ResponseDto.buildError("登录校验失败");
	}
}

